package rezetkaPages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import utils.ReportWriter;

import java.util.concurrent.TimeUnit;

/**
 * Created by IIGalytska on 11.04.14.
 */
public class CheckoutPage extends BasePage{

        public CheckoutPage(WebDriver driver) {
            super(driver);
        }





    public ConfirmationPage fillInDataPositive(String name, String mobile, String email ){

        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("reciever_name")));
        driver.findElement(By.id("reciever_name"));
        driver.findElement(By.id("reciever_name")).clear();
        driver.findElement(By.id("reciever_name")).sendKeys(name);
        ReportWriter.info("The product is ordered with the following name :" + name);

//Select Kiev
        driver.findElement(By.id("suggest_locality")).click();
        driver.findElement(By.name("0")).click();
        ReportWriter.info("The chosen location is Kiev");

        driver.findElement(By.id("reciever_phone"));
        driver.findElement(By.id("reciever_phone")).clear();
        driver.findElement(By.id("reciever_phone")).sendKeys(mobile);
        ReportWriter.info("The mobile is " + mobile);

        driver.findElement(By.id("reciever_email"));
        driver.findElement(By.id("reciever_email")).clear();
        driver.findElement(By.id("reciever_email")).sendKeys(email);
        ReportWriter.info("The email is " + email);

        driver.findElement(By.id("continue_button")).click();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        return new ConfirmationPage(driver);
    }


    public String fillInDataNegative(String name, String mobile, String email){

        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("reciever_name")));
        driver.findElement(By.id("reciever_name"));
        driver.findElement(By.id("reciever_name")).clear();
        driver.findElement(By.id("reciever_name")).sendKeys(name);
        ReportWriter.info("The product is ordered with the following name :" + name);
//Select Kiev
        driver.findElement(By.id("suggest_locality")).click();
        driver.findElement(By.name("0")).click();
        ReportWriter.info("The chosen location is Kiev");

        driver.findElement(By.id("reciever_phone"));
        driver.findElement(By.id("reciever_phone")).clear();
        driver.findElement(By.id("reciever_phone")).sendKeys(mobile);
        ReportWriter.info("The mobile is " + mobile);

        driver.findElement(By.id("reciever_email"));
        driver.findElement(By.id("reciever_email")).clear();
        driver.findElement(By.id("reciever_email")).sendKeys(email);
        ReportWriter.info("The email is " + email);

        driver.findElement(By.id("continue_button")).click();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        WebElement inputElement4 = driver.findElement(By.id("reciever_name"));

        return inputElement4.getAttribute("style");


    }


























}
